<?php
function hfr_getdate($milliseconds, $format = "Y-m-d h:i:s") {
	$date = date($format, $milliseconds/1000);
	//$datetime = new DateTime($date);
	
	return $date;
}

function hfr_debug($data) {
	echo "<pre>";
	print_r($data);
	echo "</pre>";
}

function hfr_url_exists($url) {
	$data = @file_get_contents($url);
	if (!$data) {
	    return false;
	} else {
	    return true;
	}
}


function hfr_create_id($length=16) {
	$salt       = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $len        = strlen($salt);
    $makepass   = '';
    mt_srand(10000000*(double)microtime());
    for ($i = 0; $i < $length; $i++) {
    	$makepass .= $salt[mt_rand(0,$len - 1)];
    }
    
    return $makepass;
}


function hfr_remote_get($url) {
	$result = file_get_contents($url);
	
	return $result;
}

function hfr_remote_post($url, $params = null) {
	if ($params !== null) {
		// use key 'http' even if you send the request to https://...
		$options = array('http' => array(
			'method'  => 'POST',
			'content' => http_build_query($params)
		));
		$context  = stream_context_create($options);
		$result = file_get_contents($url, false, $context);
	} else {
		$result = file_get_contents($url);
	}
	return $result;
}